﻿using Microsoft.AspNetCore.Http;
using MyWeb.Model.User;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace MyWeb.Services
{
    public class OperatorProvider: IOperatorProvider
    {
        
        private readonly IHttpContextAccessor _httpContextAccessor;
        //services.AddHttpContextAccessor();
        public OperatorProvider(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        public SysUserInfo GetUserInfo() 
        {
            var json = _httpContextAccessor.HttpContext.Request.Headers["UserInfo"];
            if (!string.IsNullOrWhiteSpace(json))
            {
                return JsonSerializer.Deserialize<SysUserInfo>(json) ?? new SysUserInfo();
            }
            return new SysUserInfo();
        }
    }
}
